import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useLoadingStore = defineStore('lading', () => {
  const count = ref(0)
 
  function open() {
    count.value++
  }
	
	function close() {
	  count.value--
	}
	function getCount () {
		return count.value
	}

  return { count, open, close, getCount }
})
export const useMenuStore = defineStore('menu', () => {
	const menus = ref([])
	const path = ref('/')
	function addMenu(menu) {
		for (const i in menus.value) {
			if (menus.value[i].path === menu.path) {
				path.value = menu.path
				return
			}
		}
		menus.value.push(menu)
		path.value = menu.path
	}
	function removeMenu(index) {
		menus.value.splice(index, 1)
	}
	function getMenus() {
		return menus.value
	}
	function getPath() {
		return path.value
	}
	return { menus, path, addMenu, removeMenu, getMenus, getPath }
}, {
	persist: {
		storage: sessionStorage
	}
})
